// Loan Calculator Class
// By Ben 22/10/2018
#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;

class TLoan{
private:
	double m_amount = 0;
	int m_years = 0;
	double m_monthly = 0;
	double m_total = 0;
	double m_total_intrest = 0;
public:
	TLoan(double amount, double apr, int years){
		double m_intrest = 0;
		double m_payments = 0;
		double monthly_payment = 0.0;

		m_amount = amount;
		m_years = years;
		//Calc interest
		m_intrest = (apr / 100) / 12;
		//Calc payments
		m_payments = (years * 12);
		//Calc monthly payments
		monthly_payment = pow(1 + m_intrest, m_payments);
		m_monthly = (m_amount*monthly_payment*m_intrest) / (monthly_payment - 1);
		//Calc the total that needs to be payed back
		m_total = (m_monthly*m_payments);
		//Calc the total interest
		m_total_intrest = (m_total - m_amount);
	}

	double Amount() const{
		return this->m_amount;
	}

	int Years() const{
		return this->m_years;
	}

	double MonthlyPayments() const{
		return this->m_monthly;
	}

	double TotalPayable()const {
		return this->m_total;
	}

	double TotalIntrest()const{
		return this->m_total_intrest;
	}
};

int main(int argc, char **argv) {
	TLoan loan(1000, 8.9, 6);
	
	//Output loan information.
	std::cout << "Amount to loan               : $" << loan.Amount() << endl;
	std::cout << "Loan will be for             : " << loan.Years() << " Years" << endl;
	std::cout << "Monthly payments             : $" << fixed << setprecision(2) << loan.MonthlyPayments() << endl;
	std::cout << "The total amount repayable:  : $" << loan.TotalPayable() << endl;
	std::cout << "Total interest               : $" << fixed << setprecision(2) << loan.TotalIntrest() << endl;

	system("pause");
	return 0;
}